#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

ll n, m;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fastpow(ll b, ll p, ll mod) {
  ll res = 1;
  while (p) {
    if (p & 1) res = (__int128_t)res * b % mod;
    b = (__int128_t)b * b % mod;
    p >>= 1;
  }
  return res;
}
ll phi(ll n) {
  ll res = n;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      res = res / i * (i - 1);
      while (n % i == 0) n /= i;
    }
  }
  if (n > 1) res = res / n * (n - 1);
  return res;
}
ll g(ll p) {
  ll x = phi(p);
  ll res = x;
  for (ll i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      ll j = x / i;
      if (fastpow(10, i, p) == 1) return i;
      if (fastpow(10, j, p) == 1) res = j;
    }
  }
  return res;
}
ll f(ll n) {
  n *= 9;
  ll d = gcd(n, 8);
  n /= d;
  if (n % 2 == 0 || n % 5 == 0) return 0;
  return g(n);
}
bool solve() {
  static int id = 0;
  ++id;
  cin >> n;
  if (!n) return false;
  cout << "Case " << id << ": " << f(n) << endl;
  return true;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  while (solve());
  return 0;
}